/**
 * TransferService.java
 */
package com.rgh.pecunia.core.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.rgh.pecunia.core.DataAccessObject;
import com.rgh.pecunia.core.PecuniaBusiness;
import com.rgh.pecunia.core.dao.ObjectifyDAO;

/**
 * 
 * @author rodrigo
 */
@Path("/transfer/")
public class TransferService {

	@POST
	@Path("/add")
	@Produces({ MediaType.TEXT_PLAIN })
	@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
	public String add(
			@FormParam("src") String source, 
			@FormParam("dst") String dest, 
			@FormParam("amt") Double amount,
			@FormParam("dsc") String description) {
		
		// Validate
		if (source == null 
				|| dest == null 
				|| amount == null 
				|| description == null) {
			return "Invalid data";
		}
		
		// Transform
		source = source.toUpperCase();
		dest = dest.toUpperCase();
		
		// Process
		DataAccessObject dao = new ObjectifyDAO();
		PecuniaBusiness biz = new PecuniaBusiness(dao);
		Boolean ok = biz.transfer(source, dest, amount, description);
		return ok.toString();
	}
}
